/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Info Cram 6000.
 *
 * The Initial Developer of the Original Code is
 * Jiří Mašek.
 * Portions created by the Initial Developer are Copyright (C) 2010
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * ***** END LICENSE BLOCK ***** */

/* ************************************************************************** *
 * ***************************** INFO CRAM 6000 ***************************** *
 * ************************************************************************** */

var infocram = {
    // === KONSTANTY === //
    DESC: " ",          // descendant combinator
    CHILD: ">",         // child combinator
    ASIB: "+",          // adjacent sibling combinator
    GSIB: "~",          // general sibling combinator
    EDITOR: "editor",
    AREA: "area",
    NAME: "name",
    URL: "url",
    READ: "read",
    USE: "use",
    ATTACH: "attach",
    AUTO: "tagname",
    ID: "id",
    IDTYPE: "idtype",
    CLASS: "classes",
    CONTENT: "contains",
    POS: "position",
    ATTR: "attributes",
    CUSTOM: "custom",
    TREE: "tree",
    // === PROMENNE === //
    selected: undefined,
    aardvark: {
        _parent: null,
        selectors: null
    },
    editor: {
        _parent: null,
        name: {
            _parent: null
        },
        area: {
            _parent: null,
            selectionStart: 0,
            selectionEnd: 0
        },
        url: {
            _parent: null
        },
        read: {
            _parent: null
        },
        widgetUse: {
            _parent: null
        },
        attach: {
            _parent: null
        },
        widgetAuto: {
            _parent: null
        },
        widgetId: {
            _parent: null
        },
        widgetClass: {
            _parent: null
        },
        widgetPos: {
            _parent: null
        },
        widgetContent: {
            _parent: null
        },
        widgetAttr: {
            _parent: null
        },
        widgetCustom: {
            _parent: null
        }
    },
    extractor: {
        _parent: null
    },
    file: {
        _parent: null
    },
    gui: {
        SELECT: "select",
        DEF: "def",
        URL: "url",
        _parent: null,
        borderElems: new Array(),
        area: "select",
        editing: "select",
        path: new Array(),
        tree: {
            _parent: null
        }
    },
    tree: {
        _parent: null,
        title: "",
        delay: 1000,
        def: { },
        url: "",
        select: { }
    }
}

infocram.aardvark._parent = infocram;
infocram.gui._parent = infocram;
infocram.gui.tree._parent = infocram.gui;
infocram.editor._parent = infocram;
infocram.editor.name._parent = infocram.editor;
infocram.editor.area._parent = infocram.editor;
infocram.editor.url._parent = infocram.editor;
infocram.editor.read._parent = infocram.editor;
infocram.editor.widgetUse._parent = infocram.editor;
infocram.editor.attach._parent = infocram.editor;
infocram.editor.widgetAuto._parent = infocram.editor;
infocram.editor.widgetId._parent = infocram.editor;
infocram.editor.widgetClass._parent = infocram.editor;
infocram.editor.widgetPos._parent = infocram.editor;
infocram.editor.widgetContent._parent = infocram.editor;
infocram.editor.widgetAttr._parent = infocram.editor;
infocram.editor.widgetCustom._parent = infocram.editor;
infocram.extractor._parent = infocram;
infocram.file._parent = infocram;
infocram.tree._parent = infocram;

/**
 * Inicializuje počáteční nastavení doplňku.
 */
infocram.init = function() {
    var _read = this.editor.read;
    var _attach = this.editor.attach;

    var read = _read.get();
    var attach = _attach.get();
    
    var child;
    var menuitem;

    // načtení aktuálně dostupných možností pro volbu "read"

    for (child in extract.read) {
        if (jQuery.isFunction(extract.read[child])) {
            menuitem = createElement("menuitem", "value=" + child + ",label=" + child);

            read.childNodes[0].appendChild(menuitem);
        }
    }

    // načtení aktuálně dostupných možností pro volbu "attach"

    for (child in extract.attach) {
        if (jQuery.isFunction(extract.attach[child])) {
            menuitem = createElement("menuitem", "value=" + child + ",label=" + child);

            attach.childNodes[0].appendChild(menuitem);
        }
    }
}